<?php
require('../database/db.php');
$mysql=new mysql();
// 分页
if($_REQUEST['page']!="" && $_REQUEST['pagesize']!=""){
	$de=$_REQUEST['page']*$_REQUEST['pagesize'];
	$size=$_REQUEST['pagesize'];
}else{
	$de=0;
	$size=10;
}
// 分页 end
// 传入经纬度
$longitude=$_REQUEST[longitude];
$latitude=$_REQUEST[latitude];
// 传入经纬度 end
// 区域id
$cityid=$_REQUEST[cityid];
// 区域id end
//传入关键词
$keywords=$_REQUEST[keywords];
if ($longitude && $latitude && $cityid && $keywords) {
	$sql = "SELECT *, (SQRT(POWER(MOD(ABS(longitude - {$longitude}),360),2) + POWER(ABS(latitude - {$latitude}),2))*160) AS distance FROM `shop` where city=".$cityid." and name like '$keywords%' ORDER BY distance limit $de,$size";
	$shop=$mysql->getAll($sql);
	$arr = array('code' => 200, 'tip' =>'查询成功' ,'shop' =>$shop);
}else{

	$arr = array('code' => 100, 'tip' =>'不存在' ,'shop' =>'不存在');
}
echo json_encode($arr);


?>